package com.hmall.search.wab;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.ItemDto;
import com.hmall.search.service.SearchSevice;
import org.apache.http.HttpHost;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.elasticsearch.search.suggest.SuggestBuilders;
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.io.IOException;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/search")
public class SearchCotroller {

    @Autowired
    private SearchSevice searchSevice;

    /**
     * 自动填充
     * @param key
     * @return
     * @throws IOException
     */
    @GetMapping("suggestion")
    public List<String> getList(String key) throws IOException {
        List<String> list = searchSevice.get(key);
        return list;
    }

    /**
     * 过滤器
     * @return
     */
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody ItemDto itemDto) throws IOException {
        Map<String, List<String>> filters = searchSevice.filters(itemDto);
        return filters;
    }
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody ItemDto itemDto) throws IOException {
        PageDTO<ItemDoc> list = searchSevice.list(itemDto);
        return list;
    }


}
